package com.mojo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.StringJoiner;

/**
 * Primary注解示例
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/9/3 10:24
 */
@Configuration
public class PrimaryConfiguration {
    private String name;

    @Bean
    public PrimaryConfiguration getConfig1() {
        return new PrimaryConfiguration();
    }

    @Bean("pc")
    //@Primary
    public PrimaryConfiguration getConfig2() {
        PrimaryConfiguration p = new PrimaryConfiguration();
        p.name = "配置名称";
        return p;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", PrimaryConfiguration.class.getSimpleName() + "[", "]")
                .add("name='" + name + "'")
                .toString();
    }
}
